package com.eastdigit.bpm.service;

import java.util.ArrayList;
import java.util.List;

import org.activiti.engine.impl.identity.Authentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import com.eastdigit.system.model.IUser;
import com.eastdigit.system.service.IUserService;
import com.eastdigit.util.StringUtil;

@Service(value = "identity")
public class IdentityUserService {
    
    @Autowired
    private IUserService userService;
    
    public List<String> splitToArray(String arrayString, String regex){
        List<String> _l = new ArrayList<String>();
        if (arrayString != null && arrayString.length() > 0) {
            String _ll[] = arrayString.split(regex);
            if (_ll != null && _ll.length > 0) {
                for (String v : _ll) {
                    _l.add(v);
                }
            }
        }
        return _l;
    }
    
    public String current() {
        return StringUtil.noNull(Authentication.getAuthenticatedUserId(),"");
    }
    
    public String user(String userCode) {
        Assert.notNull(userCode);
        IUser user = userService.queryByCode(userCode);
        return user == null ? "" : user.getId();
    }
}
